<?php
namespace Api;
use Kuyuan\WqCore\api\Api;
use Kuyuan\WqCore\util\Util;

/**
 * 红包记录，奖品信息
 * Class SendRed
 * @package Api
 */
class RedRecord extends Api
{
    private $RedRecord = null;

    public function __construct()
    {
        parent::__construct();
        $this->RedRecord = new \Controller\RedRecord();
    }

    /**
     * 获取一个红包开到的奖品
     */
    public function getAward()
    {
        $_data = array();
        $_record = $this->RedRecord->find($this->_gpc["red_id"]);
        if ($_record) {
            // 金额
            $_data["money"] = $_record["money"];
            $_data["to_go"] = $_record["to_go"];
            // 助力红包奖励
            $_share_record = $this->RedRecord->findShare($_record["id"]);
            if ($_share_record) {
                $_data["share"] = array("nickname" => $_share_record["user"]["nickname"], "money" => $_share_record["money"]);
            }
            // 卡券
            $MemberCoupon = $this->newController("MemberCoupon");
            $_coupon = $MemberCoupon->find($this->_gpc["red_id"]);
            if ($_coupon) {
                $_data["coupon"] = $_coupon["coupon"];
                $_data["coupon"]["id"] = $_coupon["id"];
            }
            $_result = array("code" => 0, "data" => $_data);
        } else {
            $_result = array("code" => 100);
        }
        Util::returns($_result);
    }

    /**
     * 通过一个红包id返回开包记录
     */
    public function getList()
    {
        Util::appointGet();
        $_data = $this->RedRecord->getList($this->_gpc["red_id"],$this->_gpc["limit"]);
        if($_data) {
            $_result = array("code"=>0,"data"=>$_data);
        } else {
            $_result = array("code"=>101);
        }
        Util::returns($_result);
    }

    /**
     * 获取用户收入记录
     */
    public function income()
    {
        Util::appointGet();
        $_list = $this->RedRecord->getUserIncome($this->_gpc["limit"]);
        if($_list && count($_list) > 0) {
            $_result = array("code"=>0,"data"=>$_list);
        } else {
            $_result = array("code"=>101);
        }
        Util::returns($_result);
    }
}